﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player : MonoBehaviour
{
    RaycastHit hit; 
    public Camera cam;
    public ChessBoard board;
    public ChessType chess;//player's chesstype
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        if (board.turn != chess)
            return;

        Play();




    }
    
    //玩家下棋函数，根据鼠标点击位置落子
    //AI继承于玩家，但是不需要鼠标点击的函数,设为虚函数
    public virtual void Play()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit))
            {
                board.PlayChess(new int[] { (int)(hit.point.x + 0.5f), (int)(hit.point.y + 0.5f) });

                //print(hit.point.x + ","+hit.point.y);
            }
        }


    }



}



